FROM alpine AS builder
RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \
    && apk add --no-cache nodejs npm
COPY ./frontend /src/frontend
WORKDIR /src/frontend
RUN npm install --registry=https://registry.npmmirror.com && npm run build

FROM maven:3.9-eclipse-temurin-17 AS packager
COPY ./backend /src/backend
COPY --from=builder /src/frontend/dist /src/backend/src/main/resources/static
WORKDIR /src/backend
ENV TZ=Asia/Shanghai
RUN ["mvn", "clean", "package", "-Dmaven.test.skip=true"]

FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/openjdk:17-jdk-alpine
COPY --from=packager /src/backend/target/*.jar /app.jar
WORKDIR /
ENV TZ=Asia/Shanghai
ENTRYPOINT [ "java", "-jar", "app.jar" ]

